//
//  JMKeyDetailRectView.m
//  OpenSesame
//
//  Created by zhangjiaming on 15/12/28.
//  Copyright © 2015年 OpenSesame. All rights reserved.
//

#import "JMKeyDetailRectView.h"

@implementation JMKeyDetailRectView

- (void)drawRect:(CGRect)rect {
    // 画最大的矩形
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextAddRect(context, CGRectMake(0, 1, self.width - 1, self.height - 2));
    CGContextSetRGBStrokeColor(context, 197.0/255.0, 197.0/255.0, 197.0/255.0, 1.0);
    CGContextStrokePath(context);
    
    // 画所有需要的行
    [self linesWithCount:5 andContextRef:context];
    
    // 前三行的分线
    CGContextMoveToPoint(context, self.width * 0.5, 0);
    CGContextAddLineToPoint(context, self.width * 0.5, 90);
    CGContextSetRGBStrokeColor(context, 197.0/255.0, 197.0/255.0, 197.0/255.0, 1.0);
    CGContextStrokePath(context);
    
}

/**
 *  画所有需要的行
 *
 *  @param count   行数
 *  @param context 图形上下文
 */
- (void)linesWithCount:(int)count andContextRef:(CGContextRef)context {
    CGFloat lineH = 30;
    for (int i = 0; i < count; i ++) {
        CGContextMoveToPoint(context, 0, lineH * (i + 1));
        CGContextAddLineToPoint(context, self.width - 1, lineH * (i + 1));
        CGContextSetRGBStrokeColor(context, 197.0/255.0, 197.0/255.0, 197.0/255.0, 1.0);
        CGContextStrokePath(context);
    }
  
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}
@end
